home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / video / paradise.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.7 KB  |  192 lines

  1. /*
  2.  * Copyright (C) 1990-1992 by Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. /*
  15.  * paradise.c    - support routines for Paradise PVGA1 and WDC90C00 family
  16.  */
  17.  
  18. #include    "vdev.h"
  19. #include    "svga.h"
  20.  
  21. /*
  22.  * table of video modes supported for PVGA1 and WDC90C00
  23.  */
  24. #define    GRAPHICS    (SVGA_MODE_SUPPORTED | SVGA_GRAPHICS_MODE)
  25. #define    TEXT        (SVGA_MODE_SUPPORTED | SVGA_TEXT_MODE)
  26.  
  27. static struct svga_mode_info paradise_modes[] =
  28. {
  29.     {    640,    480,    24,    0x72,    GRAPHICS },
  30.     {    800,    600,    15,    0x63,    GRAPHICS },
  31.     {    640,    480,    15,    0x62,    GRAPHICS },
  32.     {    1024,    768,    8,    0x60,    GRAPHICS },
  33.     {    800,    600,    8,    0x5c,    GRAPHICS },
  34.     {    640,    480,    8,    0x5f,    GRAPHICS },
  35.     {    640,    400,    8,    0x5e,    GRAPHICS },
  36.     {    320,    200,    8,    0x13,    GRAPHICS },
  37.     {    132,    28,    0,    0x47,    TEXT     },
  38.     {    80,    25,    0,    0x03,    TEXT     },
  39.     {    0,    0,    0,    0x00,    0     }
  40. };
  41.  
  42. static char    *paradise_chip_type();
  43. static int    paradise_get_memory_size();
  44. static void    paradise_bank_switch();
  45. static void    paradise_enable_extensions();
  46.  
  47. extern unsigned char    *VideoBiosAddress;
  48.  
  49. /*ARGSUSED*/
  50. int
  51. paradise_init(
  52.     char    *name,
  53.     vdev_t    *v
  54.     )
  55. {
  56.     int                r;
  57.     struct svga_mode_info    *s;
  58.     int                mem;
  59.  
  60.     if (! (r = paradise_present()))
  61.     return -1;
  62.  
  63.     paradise_enable_extensions();
  64.  
  65.     mem = paradise_get_memory_size();
  66.  
  67.     for (s = paradise_modes; s->attributes != 0; s++)
  68.     {
  69.     int    m;
  70.  
  71.     m = s->width * s->height * ((s->depth + 7) >> 3);
  72.     m /= 1024;
  73.  
  74.     if (m > mem || (! svga_mode_supported(s->bios_mode)))
  75.         s->attributes &= ~SVGA_MODE_SUPPORTED;
  76.     }
  77.  
  78.     svga_setup(v, paradise_modes, paradise_bank_switch);
  79.  
  80.     v->v_name        = paradise_chip_type();
  81.  
  82.     return 0;
  83. }
  84.  
  85. int
  86. paradise_probe()
  87. {
  88.     return paradise_present();
  89. }
  90.  
  91. int
  92. paradise_present()
  93. {
  94.     /*
  95.      * check for Paradise signature in BIOS
  96.      */
  97.     return (memcmp(VideoBiosAddress + 0x7d, "VGA=", 4) == 0);
  98. }
  99.  
  100. static void
  101. paradise_enable_extensions()
  102. {
  103.     outb(0x3ce, 0x0f);        /* unlock PR0 - PR4        */
  104.     outb(0x3cf, 0x05);
  105.  
  106.     outb(0x3d4, 0x29);        /* unlock PR1A, PR11 - PR17    */
  107.     outb(0x3d5, 0x85);
  108.  
  109.     outb(0x3c4, 0x06);        /* unlock extended sequencer    */
  110.     outb(0x3c5, 0x48);
  111. }
  112.  
  113. static char *
  114. paradise_chip_type()
  115. {
  116.     unsigned char    old, new;
  117.     char    *p;
  118.  
  119.     outb(0x3d4, 0x2b);
  120.     old = inb(0x3d5);
  121.     outb(0x3d5, 0xaa);
  122.     new = inb(0x3d5);
  123.     outb(0x3d5, old);
  124.  
  125.     if (new != 0xaa)
  126.     return "Paradise PVGA1";
  127.  
  128.     outb(0x3c4, 0x12);
  129.     old = inb(0x3c5);
  130.     outb(0x3c5, old & 0xbf);
  131.     new = inb(0x3c5) & 0x40;
  132.     if (new != 0)
  133.     {
  134.         outb(0x3c5, old);
  135.     return "Paradise WD90C00";
  136.     }
  137.  
  138.     outb(0x3c5, old | 0x40);
  139.     new = inb(0x3c5) & 0x40;
  140.     outb(0x3c5, old);
  141.     if (new == 0)
  142.     return "Paradise WD90C00";
  143.     
  144.     p = "WD90C11";
  145.     outb(0x3c4, 0x10);
  146.     old = inb(0x3c5);
  147.  
  148.     outb(0x3c5, old & 0xfb);
  149.     new = inb(0x3c5) & 0x04;
  150.     if (new != 0)
  151.     p = "Paradise WD90C10";
  152.  
  153.     outb(0x3c5, old | 0x04);
  154.     new = inb(0x3c5) & 0x04;
  155.     if (new == 0)
  156.     p = "Paradise WD90C10";
  157.  
  158.     outb(0x3c5, old);
  159.     return p;
  160. }
  161.  
  162. static int
  163. paradise_get_memory_size()
  164. {
  165.     int        x;
  166.  
  167.     outb(0x3ce, 0x0b);
  168.     x = inb(0x3cf);
  169.     x = (x >> 6) & 3;
  170.  
  171.     if (x == 0 || x == 1)
  172.     return 256;
  173.     if (x == 2)
  174.     return 512;
  175.     return 1024;
  176. }
  177.  
  178. /*
  179.  * paradise_bank_switch()
  180.  */
  181. static void
  182. paradise_bank_switch(
  183.     int        x
  184.     )
  185. {
  186.     outb(0x3ce, 0x0f);        /* unlock extended registers    */
  187.     outb(0x3cf, 0x05);
  188.  
  189.     outb(0x3ce, 0x09);
  190.     outb(0x3cf, x << 4);
  191. }
  192.